package com.qianda.qdminiapp.controller.account;


import com.qianda.qdminiapp.controller.Result;
import com.qianda.qdminiapp.domain.dto.PageRequest;
import com.qianda.qdminiapp.security.SecurityUser;
import com.qianda.qdminiapp.service.QqdAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <p>
 * 账户表 前端控制器
 * </p>
 *
 * @author cw
 * @since 2019-08-14
 */
@RestController
@RequestMapping("/qqd-account")
public class QqdAccountController {

    @Autowired
    private QqdAccountService qqdAccountService;

    /*
     * 获取用户账户信息
     * @Description
     * @Author cw
     * @Date 15:04 2019/9/2
     * @Param [user]
     * @return com.qianda.qdminiapp.controller.Result
     **/
    @GetMapping("/getAccount")
    public Result findAccount(@AuthenticationPrincipal SecurityUser user){
        return Result.success(qqdAccountService.findAccount(user.getId()));
    }

    /*
     * 获取用户账户信息
     * @Description
     * @Author cw
     * @Date 15:04 2019/9/2
     * @Param [user]
     * @return com.qianda.qdminiapp.controller.Result
     **/
    @GetMapping("/findTrade")
    public Result findTrade(@AuthenticationPrincipal SecurityUser user, PageRequest pageRequest){
        return Result.success(qqdAccountService.findTradeList(user.getId(),pageRequest));
    }

    /*
     * 余额充值
     * @Description
     * @Author cw
     * @Date 15:04 2019/9/2
     * @Param [user]
     * @return com.qianda.qdminiapp.controller.Result
     **/
    @PostMapping("/recharge/{amt}")
    public Result recharge(@AuthenticationPrincipal SecurityUser user,@PathVariable BigDecimal amt){
        Map<String, Object> recharge = qqdAccountService.recharge(user.getId(), amt);
        return Result.success(recharge);
    }

}

